#!/usr/bin/env python
# -*- coding:utf-8 -*-
import socket

ip_port = ('127.0.0.1',8009)
sk = socket.socket()
sk.connect(ip_port)
sk.settimeout(5)

while True:
    inp = raw_input('please input:')
    sk.sendall(inp)
    res_size=sk.recv(1024)
    sk.send("已收到数据长度，请传输数据吧！")
    total_size=int(res_size)    #发送的总大小
    received_size=0
    while True:             #新增死循环
        data = sk.recv(1024)
        received_size += len(data)
        if total_size==received_size:        #如果没有数据
            print data
            break           #就退出
        print data
    if inp == 'exit':
        break

sk.close()